package main.二叉树;

import common.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author tmh
 * @date 2024/7/20 15:53
 * @description
 */
public class T98验证二叉搜索树 {
    List<Integer> result  =new ArrayList<>();
    public boolean isValidBST(TreeNode root) {
        dfs(root);
        for(int i =1;i<result.size();i++){
            if(result.get(i)<=result.get(i-1)){
                return false;
            }
        }
        return true;
    }
    //中序遍历
    private void dfs(TreeNode root){
        if (root==null){
            return;
        }
        dfs(root.left);
        result.add(root.val);
        dfs(root.right);
    }
}
